* show e0 vs. csr&asr in added variable plots using panel 1985-2020
*  with Barro growth regressions

discard
cd "~/Documents/econ/research/current/cognitive/estimation/dofiles"

// produce table with Barro growth regressions showing e0 vs. asr&csr //

use ../data/growth_panel, clear
xtset isonum year, delta(5)

label var lgdppw "\(ln(y_0)\)"
label var PRI "Institutions (0-100)"
label var trade_open "Trade openness (\% of GDP)"
label var e0 "Life expectancy (years)"
label var yr_sch "Schooling (years)"
label var csr "Child survival (per 1000)"
label var asr "Adult survival (per 1000)"
label var csr_lag "Child survival, previous generation"

tab year if year>=1985, gen(yd) // create year dummies after 1985
drop yd1

local exoglag 4
local gvars "gPWT5 lgdppw PRI trade_open yr_sch yd*"
local xtabgmm "gmm(lgdppw, laglimits(3 6))"
local xtabiv "iv(PRI trade_open yr_sch yd*) twostep robust"
local outopts "se varlabel squarebrack drop(yd*) starlevels(5 1 .1)"
local avopts "msize(*0.36) yscale(range(-3 3.1)) ylim(-3 3.1) xsize(4) ysize(4) nocoef"

// e0
xtabond2 `gvars' e0, `xtabgmm' gmm(e0, laglimits(1 `exoglag')) ///
	`xtabiv' svmat
outreg, `outopts' nodisplay ctitle("", "(1)" \ "", "Life" \ "", "expectancy")
	
xtavplot e0, title(Life expectancy)	///
		ytitle("e(GDP per worker growth | X)" " ")	///
		xtitle("e(Life expectancy | X)")			///
		ylabel(-3(1)3, noticks nolabel) xlabel(-10(10)10) ///
		xlim(-20 20) name(e0) `avopts'
graph export "../../draft/images/e0_vs_growth.pdf", replace

// asr & csr
xtabond2 `gvars' asr csr, `xtabgmm' gmm(asr csr,  ///
	laglimits(1 `exoglag')) `xtabiv' svmat
sum asr csr if e(sample)

xtavplot asr, title(Adult survival)	///
		ytitle("")	///
		xtitle("e(Adult survival rate | X)")	///
		ylabel(-3(1)3, angle(horizontal)) xlabel(-50(50)50) ///
		xlim(-60 60) name(asr) `avopts'
graph export "../../draft/images/asr_vs_growth.pdf", replace
		
xtavplot csr, title(Child survival)	///
		ytitle(" ")	///
		xtitle("e(Child survival rate | X)")	///
		ylabel(-3(1)3, noticks nolabel) xlabel(-50(50)50) ///
		xscale(range(-60 60)) ///
		xlim(-60 60) name(csr) `avopts'
graph export "../../draft/images/csr_vs_growth.pdf", replace

graph combine e0 asr csr, rows(1) ysize(2) iscale(*1.2)
graph export "../../draft/images/e0_csr_vs_growth.pdf", replace

outreg, `outopts' ctitle("", "(2)" \ "", "Current" \ "", "CSR") merge
